<?php
	require_once(dirname(__FILE__).'/easy_runner.php');
	require_once(dirname(__FILE__).'/../router_factory.php');
	
	Mock::generatePartial(
		'RouterFactory',
		'MockRouterFactory',
		array('createPattern', 'createRouter')
	);
	
	Mock::generate('Router');
	Mock::generate('RoutePattern');
	
	class RouterFactoryTests extends UnitTestCase {
		public function testRouterCanCreateRouterFromIniFile() {	
			$first = new MockRoutePattern();
			$first->expectOnce('setDefaultFor', array('action', 'articles'));
			
			$second = new MockRoutePattern();
			$second->expectOnce('setDefaultFor', array('action', 'items'));
			$second->expectOnce('setRegexRuleFor', array('id', '/[0-9]+/'));
			
			$router = new MockRouter();
			$router->expectArgumentsAt(0, 'addPattern', array($first));
			$router->expectArgumentsAt(1, 'addPattern', array($second));
			$router->expectCallCount('addPattern', 2);
			$router->expectOnce('setDefaultParameters', array(array('action' => '404')));
			
			$factory = new MockRouterFactory();
			$factory->expectArgumentsAt(0, 'createPattern', array('articles/:sid'));
			$factory->expectArgumentsAt(1, 'createPattern', array('items/:id'));
			$factory->setReturnValueAt(0, 'createPattern', $first);
			$factory->setReturnValueAt(1, 'createPattern', $second);
			$factory->expectCallCount('createPattern', 2);
			$factory->setReturnValue('createRouter', $router);
			
			$result = $factory->createFromIniFile(dirname(__FILE__).'/support/example_config.ini');			
			$this->assertIdentical($result, $router);
		}
	}
	
	if(EasyRunner::isRunner()) {
		EasyRunner::run(new RouterFactoryTests());
	}
?>